# coding: utf-8
import web
from web import form

__all__ = [
    'form_login', 'form_signup',
]

# regexp
v_username = form.regexp(r'.{3,15}$', u'must be between 3-15 characters')
v_password = form.regexp(r'.{3,15}$', u'must be between 3-15 characters')
v_email = form.regexp(r'.*@.*', u'must be email')

# define forms
form_login = form.Form(
    form.Textbox('username', form.notnull,
        v_username,
        size = 16,
        description = u'Use Name',
    ),
    form.Password('password', form.notnull,
        v_password,
        size = 16,
        description = u'Password',
    ),
    form.Button('submit'),
)

form_signup = form.Form(
    form.Textbox('email', form.notnull,
        v_email,
        size = 16,
        description = u'Email',
    ),
    form.Textbox('username', form.notnull,
        v_username,
        size = 16,
        description = u'Use Name',
    ),
    form.Password('password', form.notnull,
        v_password,
        size = 16,
        description = u'Password',
    ),
    form.Password('repeat', form.notnull,
        size = 16,
        description = u'Repeat',
    ),
    form.Button('submit', type = 'submit', description = u''),
    validators = [form.Validator("Password did't match", lambda x: x.password == x.repeat)],
)
